package com.example.workmode.UserPreferences;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Gravity;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.NumberPicker.OnValueChangeListener;

public class BreakDurationSetting extends Activity {

	String title;
	String var;
	SharedPreferences pref;
	int defaultValue;
	int currentValue;
	
    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        
        pref = getSharedPreferences("MyPrefs", 0);
        defaultValue = pref.getInt("breakDuration",	1);
        title = "Set Break Duration (Minute)";
        var = "breakDuration";
        	
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        LinearLayout layout = new LinearLayout(this);
        NumberPicker aNumberPicker = new NumberPicker(this);
        
        aNumberPicker.setMaxValue(100);
        aNumberPicker.setMinValue(0);
        aNumberPicker.setValue(defaultValue);
        aNumberPicker.setWrapSelectorWheel(true);
        aNumberPicker.setClickable(false);
        aNumberPicker.setEnabled(true);
        aNumberPicker.setGravity(Gravity.CENTER);
        aNumberPicker.setOnValueChangedListener(new OnValueChangeListener() {
            @Override
             public void onValueChange(NumberPicker picker, int oldVal, int newVal){
            	currentValue = newVal;
             }
        });
        layout.setGravity(Gravity.CENTER);
        layout.addView(aNumberPicker);
        alert.setTitle(title);
        alert.setView(layout);
              
        alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				
			}
		});
        
        alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				SharedPreferences pref = getSharedPreferences("MyPrefs", 0);
				SharedPreferences.Editor editor = pref.edit(); 
				editor.putInt(var, currentValue);
				editor.commit();
			}
		});
        
        
        
        alert.show();
   }
}
